var e = require;
var t = module;
var o = exports;
var ii, nn = this && this.__extends || (ii = function (t, e) {
    return (ii = Object.setPrototypeOf || {
        __proto__: []
    }
        instanceof Array &&
        function (t, e) {
            t.__proto__ = e
        } ||
        function (t, e) {
            for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
        })(t, e)
},
    function (t, e) {
        function o() {
            this.constructor = t
        }
        ii(t, e),
            t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
    }
),
    rr = this && this.__awaiter ||
        function (t, e, o, i) {
            return new (o || (o = Promise))(function (n, a) {
                function r(t) {
                    try {
                        l(i.next(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function s(t) {
                    try {
                        l(i.
                            throw(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function l(t) {
                    var e;
                    t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
                        t(e)
                    })).then(r, s)
                }
                l((i = i.apply(t, e || [])).next())
            })
        };
var oo = (this && this.__decorate) ||
    function (e, t, a, n) {
        var i,
            o = arguments.length,
            s = o < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, a)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, a, n);
        else
            for (var r = e.length - 1; r >= 0; r--)
                (i = e[r]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, a, s) : i(t, a)) || s);
        return o > 3 && s && Object.defineProperty(t, a, s), s;
    };
Object.defineProperty(o, "__esModule", { value: !0 });
var a = e("NotifyEventType"),
    n = e("GlobalParams"),
    i = e("AssetsManager"),
    r = e("ModuleUI"),
    s = e("CommonHelper"),
    l = e("EquipInfo"),
    _ = e("equip_item_info"),
    c = e("sdkConfig"),
    d = e("AD"),
    h = e("Toast"),
    u = e("BuyEquipInfo"),
    p = cc._decorator,
    m = p.ccclass,
    f = p.property,
    v = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.equip_item = null),
                (t.equip_view = null),
                (t.btn_view = null),
                (t.nom_equip_view = null),
                (t.equip_name_label = null),
                (t.equip_icon_sprite = null),
                (t.int_info_node = null),
                (t.equip_skill_list = []),
                (t.use_equip_view = null),
                (t.buy_btn = null),
                (t.sell_btn = null),
                (t.have_coin_num_label = null),
                (t.equip_type = ["nom", "att", "hp", "speed", "cool"]),
                (t.choose_equip_info = null),
                (t.sell_index = 0),
                t
            );
        }
        return (
            nn(t, e),
            (t.prototype.initView = function () {
                e.prototype.initView.call(this);
                for (var t = 0; t < 3; t++) {
                    for (var o = 0; o < 4; o++)
                        (n = cc.instantiate(this.equip_item)).setParent(this.equip_view.children[t]);
                    for (o = 0; o < 6; o++) {
                        var n;
                        ((n = cc.instantiate(this.equip_item)).x = 0), n.setParent(this.nom_equip_view.children[t]);
                    }
                }
                this.attachEvent(a.default.SEND_CHOOSE_EQUIP_INFO, this.showChooseEquipInfo, this),
                    this.showBtnViewInfo("nom"),
                    this.showUseEquip(),
                    this.showHaveCoin();
            }),
            (t.prototype.addEvent = function () {
                this.attachEvent(a.default.SEND_UPDATE_MATCH_PLAYER_INFO, this.showHaveCoin, this);
            }),
            (t.prototype.showHaveCoin = function () {
                this.have_coin_num_label.string = "" + n.GlobalParams.MatchGamePlayer[n.GlobalParams.MatchMyIndex].coin;
            }),
            (t.prototype.OnClick = function (t) {
                var o = this;
                e.prototype.OnClick.call(this, t);
                var i = t.node.name;
                switch (i) {
                    case "back_btn":
                        c.default.platform == c.EPlatform.TikTok && d.default.getInstance().ResumeRecorder(),
                            this.closeThisPopup();
                        break;
                    case "nominate_equip_btn":
                        this.showBtnViewInfo("nom");
                        break;
                    case "equip_att_btn":
                        this.showBtnViewInfo("att");
                        break;
                    case "equip_hp_btn":
                        this.showBtnViewInfo("hp");
                        break;
                    case "equip_speed_btn":
                        this.showBtnViewInfo("speed");
                        break;
                    case "equip_cooling_btn":
                        this.showBtnViewInfo("cool");
                        break;
                    case "equip_0":
                    case "equip_1":
                    case "equip_2":
                    case "equip_3":
                    case "equip_4":
                    case "equip_5":
                        var r = s.default.getNameType(i, "equip_");
                        this.sell_index = r;
                        var _ = n.GlobalParams.MatchGamePlayer[n.GlobalParams.MatchMyIndex].equip_info;
                        if (_[r] > 0) {
                            for (var p = 0; p < this.use_equip_view.childrenCount; p++)
                                this.use_equip_view.children[p].getChildByName("choose").active = p == r;
                            var m = l.default.eqquip_info[_[r]];
                            this.emitEvent(a.default.SEND_CHOOSE_EQUIP_INFO, { use: !0, info: m });
                        }
                        break;
                    case "buy_btn":
                        var f = this.choose_equip_info.eq_sale,
                            v = n.GlobalParams.MatchGamePlayer[n.GlobalParams.MatchMyIndex].equip_info,
                            g = [],
                            y = 0;
                        for (p = 0; p < this.choose_equip_info.eq_need.length; p++)
                            -1 != v.indexOf(this.choose_equip_info.eq_need[p]) &&
                                ((f -= l.default.eqquip_info[this.choose_equip_info.eq_need[p]].eq_sale),
                                    g.push(v.indexOf(this.choose_equip_info.eq_need[p])));
                        for (p = 0; p < v.length; p++) v[p] > 0 && y++;
                        if (f == this.choose_equip_info.eq_sale && y > 5)
                            return void cc.log("=====已达到购买上限=====");
                        if (n.GlobalParams.MatchGamePlayer[n.GlobalParams.MatchMyIndex].coin >= f) {
                            for (p = 0; p < g.length; p++) v[g[p]] = 0;
                            for (
                                v[v.indexOf(0)] = this.choose_equip_info.eq_ID,
                                n.GlobalParams.MatchGamePlayer[n.GlobalParams.MatchMyIndex].coin -= f,
                                n.GlobalParams.MatchGamePlayer[n.GlobalParams.MatchMyIndex].equip_info = v,
                                this.showUseEquip(),
                                u.default.playerBuyEquipInfo(n.GlobalParams.MatchMyIndex, function () {
                                    o.emitEvent(
                                        a.default.SEND_UPDATE_BUY_EQUIP_NEW_ADD_INFO,
                                        n.GlobalParams.MatchMyIndex
                                    );
                                }),
                                p = 0;
                                p < this.choose_equip_info.eq_need.length;
                                p++
                            ) {
                                var I = n.GlobalParams.MyNomEquipInfo.indexOf(this.choose_equip_info.eq_need[p]);
                                -1 != I && n.GlobalParams.MyNomEquipInfo.splice(I, 1);
                            }
                            n.GlobalParams.MyNomEquipInfo.splice(
                                n.GlobalParams.MyNomEquipInfo.indexOf(this.choose_equip_info.eq_ID),
                                1
                            ),
                                this.emitEvent(a.default.SEND_UPDATE_MATCH_PLAYER_INFO);
                        } else h.default.showNewToast("金币不足");
                        break;
                    case "sell_btn":
                        if (-1 == this.sell_index) return void h.default.showNewToast("选择要出售的装备");
                        (n.GlobalParams.MatchGamePlayer[n.GlobalParams.MatchMyIndex].coin +=
                            0.5 * this.choose_equip_info.eq_sale),
                            (n.GlobalParams.MatchGamePlayer[n.GlobalParams.MatchMyIndex].equip_info[
                                this.sell_index
                            ] = 0),
                            this.showUseEquip(),
                            this.emitEvent(a.default.SEND_UPDATE_MATCH_PLAYER_INFO),
                            u.default.playerBuyEquipInfo(n.GlobalParams.MatchMyIndex, function () {
                                o.emitEvent(a.default.SEND_UPDATE_BUY_EQUIP_NEW_ADD_INFO, n.GlobalParams.MatchMyIndex);
                            }),
                            (this.sell_index = -1),
                            (this.sell_btn.interactable = !1);
                }
            }),
            (t.prototype.showBtnViewInfo = function (e) {
                for (var t = 0; t < 5; t++) this.btn_view.children[t].children[0].active = e == this.equip_type[t];
                "nom" != e ? this.showEquipViewInfo(e) : this.showNomEquipInfo(),
                    (this.equip_view.active = "nom" != e),
                    (this.nom_equip_view.active = "nom" == e);
            }),
            (t.prototype.showEquipViewInfo = function (e) {
                var t = [];
                "att" == e
                    ? (t = l.default.equip_att_info)
                    : "hp" == e
                        ? (t = l.default.equip_hp_info)
                        : "speed" == e
                            ? (t = l.default.equip_speed_info)
                            : "cool" == e && (t = l.default.equip_cooling_info);
                for (var o = 0; o < 3; o++)
                    for (var n = 0; n < 4; n++) this.equip_view.children[o].children[n].active = !1;
                for (o = 0; o < t.length; o++) {
                    var i = l.default.eqquip_info[t[o]],
                        r = this.equip_view.children[i.eq_level - 1].children[i.eq_index];
                    r.getComponent(_.default).showEquipInfo(i), (r.active = !0);
                }
                this.emitEvent(a.default.SEND_CHOOSE_EQUIP_INFO, { use: !1, info: l.default.eqquip_info[t[0]] });
            }),
            (t.prototype.showNomEquipInfo = function () {
                for (
                    var e =
                        l.default.equip_nominate_info[
                            n.GlobalParams.MatchGamePlayer[n.GlobalParams.MatchMyIndex].role_id
                        ].nom_equip,
                    t = null,
                    o = 0;
                    o < e.length;
                    o++
                ) {
                    var i;
                    i = l.default.eqquip_info[e[o]];
                    for (var r = 0; r < i.eq_need.length; r++) {
                        var s = l.default.eqquip_info[i.eq_need[r]];
                        this.addNomEquipItem(s, o), null == t && (t = s);
                    }
                    1 == i.eq_need.length && this.addNomEquipItem({ eq_ID: -1, eq_level: 3 }, o),
                        this.addNomEquipItem(i, o);
                }
                this.emitEvent(a.default.SEND_CHOOSE_EQUIP_INFO, { use: !1, info: t });
            }),
            (t.prototype.addNomEquipItem = function (e, t) {
                var o = null;
                (o = this.nom_equip_view.children[e.eq_level - 1].children[t]).getComponent(_.default).showEquipInfo(e),
                    (o.active = !0);
            }),
            (t.prototype.showChooseEquipInfo = function (e, t) {
                this.choose_equip_info = t.info;
                var o = t.info;
                (this.equip_name_label.string = "" + o.eq_name),
                    (this.equip_icon_sprite.spriteFrame = i.default
                        .getInstance()
                        .getEquipIconFrame("equip_" + o.eq_ID));
                for (var a = 0; a < this.equip_skill_list.length; a++)
                    (this.equip_skill_list[a].active = o.eq_skill[a]),
                        this.equip_skill_list[a].active &&
                        ((this.equip_skill_list[a].getChildByName("type").getComponent(cc.Label).string =
                            o.eq_skill[a]),
                            (this.equip_skill_list[a].getChildByName("info").getComponent(cc.Label).string =
                                o.eq_skill_des[a]));
                for (a = 0; a < 2; a++)
                    (this.int_info_node.children[a].active = o.eq_int[a]),
                        this.int_info_node.children[a] &&
                        (this.int_info_node.children[a].children[0].getComponent(cc.Label).string = o.eq_int[a]);
                if (((this.buy_btn.interactable = !t.use), (this.sell_btn.interactable = t.use), !t.use))
                    for (a = 0; a < this.use_equip_view.childrenCount; a++)
                        this.use_equip_view.children[a].getChildByName("choose").active = !1;
            }),
            (t.prototype.showUseEquip = function () {
                for (
                    var e = n.GlobalParams.MatchGamePlayer[n.GlobalParams.MatchMyIndex].equip_info, t = 0;
                    t < this.use_equip_view.childrenCount;
                    t++
                ) {
                    var o = this.use_equip_view.children[t];
                    (o.getChildByName("equip").getComponent(cc.Sprite).spriteFrame =
                        0 == e[t] ? null : i.default.getInstance().getEquipIconFrame("equip_" + e[t])),
                        (o.getChildByName("choose").active = !1);
                }
            }),
            oo([f(cc.Node)], t.prototype, "equip_item", void 0),
            oo([f(cc.Node)], t.prototype, "equip_view", void 0),
            oo([f(cc.Node)], t.prototype, "btn_view", void 0),
            oo([f(cc.Node)], t.prototype, "nom_equip_view", void 0),
            oo([f(cc.Label)], t.prototype, "equip_name_label", void 0),
            oo([f(cc.Sprite)], t.prototype, "equip_icon_sprite", void 0),
            oo([f(cc.Node)], t.prototype, "int_info_node", void 0),
            oo([f(cc.Node)], t.prototype, "equip_skill_list", void 0),
            oo([f(cc.Node)], t.prototype, "use_equip_view", void 0),
            oo([f(cc.Button)], t.prototype, "buy_btn", void 0),
            oo([f(cc.Button)], t.prototype, "sell_btn", void 0),
            oo([f(cc.Label)], t.prototype, "have_coin_num_label", void 0),
            oo([m], t)
        );
    })(r.default);
o.default = v;
